/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Excersize2_Swing;

import battleshipgame.logic.Player;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JButton;

/**
 *
 * @author אלירן
 */
public class PlayerButton extends JButton{
        final private Player player ;
        int id;
        private BattleshipGameJFrame frameReferrence ;
    

    public PlayerButton( final Player player, BattleshipGameJFrame frame) {
        super(player.getName());
        this.player = player;
        this.id= player.getId();
        frameReferrence = frame ;
        this.setBackground(Color.GREEN);
        //this.setForeground(Color.blue);
        this.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        //this.add( lable );
        //this.setForeground(Color.red);
        this.setMinimumSize(new Dimension(20, 20));
        this.setMaximumSize(new Dimension(20, 20));
        this.setPreferredSize(new Dimension(20, 20));
        this.setVisible(true);
        this.repaint();
        addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
            }

            public void mouseClicked(java.awt.event.MouseEvent evt) {
                SquareButtonMouseClicked(evt);
            }

            private void SquareButtonMouseClicked(MouseEvent evt) {
                frameReferrence.changePlayerFocus(id);
            }
        });
    }
    
    
}
